<?php
/**
 * @user:andy
 * @date:2021/7/10
 * @company:http://www.sjdphp.com
 * @desc:
 */

namespace app\admin\business;


use app\common\server\Json;
use app\common\server\SystemLog;

class BackCurrentBus extends BusBase
{
    public static function getLists($term, $field = '', $page = 0, $limit = 0, $order = '')
    {
        $model = self::getModelExample();

        ## 查询操作
        try{
            $lists = $model->where($term)->field($field)->page($page,$limit)->order($order)->select();
            $count = $model->where($term)->count();
        }catch(\Exception $e){
            SystemLog::insertLog($e->getMessage());
            return Json::error("系统繁忙,请稍后重试");
        }

        if(!empty($lists) && !empty($count)){
            ## 判断开始时间与结束时间并处理
            $time = time();
            foreach($lists as $k => $v){
                if($v["start_time"] > $time){ ##开始时间大于当前时间
                    $lists[$k]["status_name"] = '未开始';
                } else if($v["end_time"] < $time){ ## 结束时间小于当前时间
                    $lists[$k]["status_name"] = '已过期';
                }else{
                    $lists[$k]["status_name"] = '使用中';
                }
                $lists[$k]["start_time"] = date("Y-m-d H:i:s",$v["start_time"]);
                $lists[$k]["end_time"]   = date("Y-m-d H:i:s",$v["end_time"]);
            }
            return Json::normal('获取成功',$lists);
        }else{
            return Json::error('空数据');
        }
    }
}